package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     *  分页查询
     * @param queryPageBean
     * @return
     */
    Page<Setmeal> findPage(QueryPageBean queryPageBean);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from t_setmeal where id = #{id}")
    Setmeal findById(Integer id);

    /**
     * 修改套餐
     * @param setmeal
     */

    void update(Setmeal setmeal);

    /**
     * 删除套餐关联关系
     * @param id
     */
    @Delete("delete from t_setmeal_checkgroup where setmeal_id = #{id}")
    void deleteCheckGroupAndSetmeal(Integer id);

    /**
     * 增加套餐关联关系
     * @param
     * @param checkGroupId
     */
    @Insert("insert IGNORE into t_setmeal_checkgroup(setmeal_id,checkgroup_id) " +
            "values(#{setmealId},#{checkGroupId})")
    void addCheckGroupAndSetmeal(Integer setmealId, Integer checkGroupId);

    /**
     * 增加套餐
     * @param setmeal
     */

    void add(Setmeal setmeal);

    /**
     * 删除套餐
     * @param id
     */
    @Delete("delete from t_setmeal where id = #{id}")
    void deleteById(Integer id);

    void setSetmealAndCheckGroup(Map<String, Integer> map);

    @Select("select * from t_setmeal")
    List<Setmeal> findAll();

    Object findById4Detail(Integer id);
}
